package utils

import (
	"crypto/md5"
	"errors"
	"fmt"
	"golang.org/x/crypto/bcrypt"
)

func Md5Text(text string) string {
	return fmt.Sprintf("%x", md5.Sum([]byte(text))) //返回md5的校验和
}

func HashAdd(password string) string {
	hash, err := bcrypt.GenerateFromPassword([]byte(password), 0)
	if err != nil {
		panic(errors.New("hash Err"))
		return ""
	}
	return string(hash)
}

func HashPJ(hash, password string) bool {
	return bcrypt.CompareHashAndPassword([]byte(hash), []byte(password)) == nil
}
